<html>
<head><meta charset="utf-8"><title>MIR lookup · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/MIR.20lookup.html">MIR lookup</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="227187094"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/MIR%20lookup/near/227187094" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Michael Coblenz <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/MIR.20lookup.html#227187094">(Feb 21 2021 at 19:03)</a>:</h4>
<p>Newbie question here: how do get the MIR for a given DefId? I found mir_build, but it appear to only work for bodies, not arbitrary items.</p>



<a name="227188716"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/MIR%20lookup/near/227188716" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/MIR.20lookup.html#227188716">(Feb 21 2021 at 19:31)</a>:</h4>
<p>Not all items have MIR. MIR specifically represents instructions you execute, so e.g. structs and enums don't have MIR</p>



<a name="227188850"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/MIR%20lookup/near/227188850" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tm <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/MIR.20lookup.html#227188850">(Feb 21 2021 at 19:34)</a>:</h4>
<p>Implementation of <code>instance_mir</code> function might be helpful.</p>



<a name="227189385"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/MIR%20lookup/near/227189385" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Michael Coblenz <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/MIR.20lookup.html#227189385">(Feb 21 2021 at 19:43)</a>:</h4>
<p>Aha, this is helpful. Well, maybe I should explain what I'm trying to do: I have a TyS that represents a type with a type parameter. I want to know the value of the type parameter in that instance (not the name of the parameter, but the value that is being substituted for it in this instance).</p>



<a name="227189398"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/MIR%20lookup/near/227189398" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Michael Coblenz <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/MIR.20lookup.html#227189398">(Feb 21 2021 at 19:43)</a>:</h4>
<p>I was thinking if I got the MIR, it would have the substitution already done.</p>



<a name="227189462"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/MIR%20lookup/near/227189462" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Michael Coblenz <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/MIR.20lookup.html#227189462">(Feb 21 2021 at 19:44)</a>:</h4>
<p>I can get the HIR, but that only tells me the name of the parameter. I'm currently looking at "substs".</p>



<a name="227189580"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/MIR%20lookup/near/227189580" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/MIR.20lookup.html#227189580">(Feb 21 2021 at 19:46)</a>:</h4>
<p>Where do you get this type from? The substs are not associated to a type, but to the specific instantiation of the function that contains it.</p>



<a name="227190078"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/MIR%20lookup/near/227190078" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Michael Coblenz <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/MIR.20lookup.html#227190078">(Feb 21 2021 at 19:55)</a>:</h4>
<p>Well, concretely, I'm doing codegen, so I have a TyAndLayout.</p>



<a name="227190150"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/MIR%20lookup/near/227190150" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/MIR.20lookup.html#227190150">(Feb 21 2021 at 19:56)</a>:</h4>
<p>A TyAndLayout should already be monomorphized.</p>



<a name="227190385"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/MIR%20lookup/near/227190385" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Michael Coblenz <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/MIR.20lookup.html#227190385">(Feb 21 2021 at 20:01)</a>:</h4>
<p>Ah, so there's no parameter there. I have to look at the monomorphized type and answer my question from that.</p>



<a name="227190643"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/MIR%20lookup/near/227190643" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Michael Coblenz <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/MIR.20lookup.html#227190643">(Feb 21 2021 at 20:05)</a>:</h4>
<p>That's not quite what I'm seeing. When I log the type, I get  TyAndLayout { ty: GcRef&lt;dyn GcTrace&gt; … } . I'm looking to extract the "dyn GcTrace" component from that.</p>



<a name="227190734"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/MIR%20lookup/near/227190734" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Michael Coblenz <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/MIR.20lookup.html#227190734">(Feb 21 2021 at 20:07)</a>:</h4>
<p>And indeed, when I look in the substs, I get what I want.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>